<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>聊天室 | 登录</title>
    <!-- 引入bootstrap样式 -->
    <!-- CSS only -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
    <link rel="stylesheet" href="index.css">
</head>

<body class="bg-light d-flex justify-content-center">

    <div class="login-container shadow-lg  bg-body rounded mt-5">
        <div class="login-head p-3 text-center  bg-success bg-gradient text-light">聊一聊</div>
        <div class="login-body p-3 border-bottom">
            <form action="#" id="loginForm">
                <div class="mb-3">
                    <label for="name" class="form-label">姓 名</label>
                    <input type="text" class="form-control" id="name" placeholder="请输入姓名">
                </div>
                <div class="mb-3">
                    <label for="room" class="form-label">房 间</label>
                    <select class="form-select" id="room">
                        <option value='' selected>请选择房间</option>
                        <option value="Javascript">Javascript</option>
                        <option value="Html">Html</option>
                        <option value="Css">Css</option>
                    </select>
                </div>
                <div class="d-grid gap-2 mt-5">
                    <button type="submit" class="btn btn-success">登 录</button>
                </div>
            </form>
        </div>
    </div>

</body>
<!-- 引入bootstrap的js -->
<!-- JavaScript Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
    integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
    crossorigin="anonymous"></script>

<script>
    var loginForm = document.getElementById('loginForm');
    loginForm.addEventListener('submit', (e) => {
        e.preventDefault();
        let name = document.getElementById('name').value;
        let room = document.getElementById('room').value;
        if (!name.trim()) {
            alert('姓名必填!')
            return
        }
        if (!room) {
            alert('请选择房间!')
            return
        }
        window.location.replace(`/room.html?name=${encodeURI(name)}&room=${encodeURI(room)}`, '_self')
    })

</script>

</html>